﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DSLOrder
{
    public partial class Top : Form
    {
        public Top()
        {
            InitializeComponent();
        }

        Common Init = new Common();
        MsSqlHelper mssql = new MsSqlHelper();

        private void txtSearch_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                Query();
            }
        }

        private void Top_Load(object sender, EventArgs e)
        {
            comboBox1.Text = "100";
            string select = comboBox1.Text;
            string sql = "select top " + select + " rtrim(spid) as spid,rtrim(spbh) as spbh,rtrim(spmch) as spmch,rtrim(shpgg) as shpgg,rtrim(dw) as dw,rtrim(shengccj) as shengccj,rtrim(pizhwh) as pizhwh,rtrim(zjm) as zjm,rtrim(denglrq) as denglrq from [spkfk] where leibie not in('中药材','中药饮片') and beactive='是' order by denglrq desc";
            DataTable dt = mssql.ExecuteDt(sql);
            dGV.DataSource = dt;
            try
            {
                Common.AutoSizeColumn(dGV);
                dGV.Columns["spid"].HeaderText = "id";
                dGV.Columns["spbh"].HeaderText = "商品编号";
                dGV.Columns["spmch"].HeaderText = "商品名称";
                dGV.Columns["shpgg"].HeaderText = "规格";
                dGV.Columns["dw"].HeaderText = "单位";
                dGV.Columns["shengccj"].HeaderText = "生产厂家";
                dGV.Columns["pizhwh"].HeaderText = "批准文号";
                dGV.Columns["zjm"].HeaderText = "拼音码";
                dGV.Columns["denglrq"].HeaderText = "登记日期";
                dGV.Columns["spid"].Visible = false;
                dGV.Columns["zjm"].Visible = false;
            }
            catch (Exception ex)
            {
                Init.WriteLog(ex.ToString(), true);
                MessageBox.Show("这也能出错，请重试\r\n" + ex.Message.ToString());
            }
        }

        private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
        {
            Query();
        }

        public void Query()
        {
            string select = comboBox1.Text;
            string Search = txtSearch.Text;
            string sql = "select top "+select+" rtrim(spid) as spid,rtrim(spbh) as spbh,rtrim(spmch) as spmch,rtrim(shpgg) as shpgg,rtrim(dw) as dw,rtrim(shengccj) as shengccj,rtrim(pizhwh) as pizhwh,rtrim(zjm) as zjm,rtrim(denglrq) as denglrq from [spkfk] where leibie not in('中药材','中药饮片') and beactive='是' and (spbh like '%" + Search + "%' or spmch like '%" + Search + "%' or zjm like '%" + Search + "%') order by denglrq desc";
            DataTable dt = mssql.ExecuteDt(sql);
            dGV.DataSource = dt;
        }
    }
}
